<?php
/**
 * Created by PhpStorm.
 * User: Fan
 * Date: 2018/8/15
 * Time: 21:23
 */

namespace App\apitransifer;


use League\Fractal\TransformerAbstract;
use Modules\Shop\Entities\Article;

class ArticlerTransfer extends TransformerAbstract
{
    # 定义可以include可用的字段
    protected $availableIncludes = ['category'];
    public function transform(Article $article)
    {
        return [
            'id' => $article['id'],
            'title' => $article['title'],
            'bewrite' => $article['bewrite'],
            'content' => $article['content'],
            'thumb' => $article['thumb'],
        ];
    }
    public function includeCategory(Article $article)
    {
        return $this->item($article->category,new CategoryTransformer());
    }
}